

#include <ros/ros.h>
// #include <geometry_msgs/Twist.h>
#include <nav_msgs/Odometry.h>
#include <std_msgs/Float64.h>
#include <geometry_msgs/PoseStamped.h>


double distancepoint;
const double firstdis=36;//yiquanchangdu 
bool maplive=true;



void DistanceCallback(const std_msgs::Float64& distance)
{
    distancepoint=distance.data;
}

int main(int argc, char** argv)
{
    ros::init(argc, argv, "maplive");
    ros::NodeHandle nh;
    ros::Subscriber sub_dist = nh.subscribe("/distance",1,DistanceCallback);
    ros::Rate r(48);
    ROS_INFO("maplive start successfully.");
    while(ros::ok())
    {
        if(maplive)
        {
            ros::spinOnce();
            if(distancepoint>firstdis-1)
            {
                ROS_INFO("Map live!");
                system("rosrun map_server map_saver -f /home/racecar/map");
                maplive = false;
                
                system("rosnode kill map_node");

                system("rosrun map_server map_server /home/racecar/map.yaml");
                // system("roslaunch nav_teb amcl.launch");
                // system("roslaunch nav_teb navigation_teb.launch");
                ros::shutdown();
            }
        }
        
        r.sleep();
    }
    return 0;
}